package cn.fl.project.controller;

import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.project.service.IPrjLnkCompBkAccService;
import cn.fl.project.service.IPrjLnkCompService;
import cn.fl.project.vo.PrjLnkCompBkAccVO;
import cn.fl.project.vo.PrjLnkCompVO;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.vo.SysUlFilesRecVO;
import cn.fl.upload.constant.UploadConstant;
import com.alibaba.fastjson.JSON;
import fl.constant.facade.framework.constant.BusinessIdConstant;
import fl.flow.facade.flow.constant.FlowConstant;
import fl.flow.facade.flow.dto.FlowStartParamsDTO;
import fl.flow.facade.flow.dto.FlowStartedDTO;
import fl.spl.facade.framework.constant.SplSystemConstant;
import fl.spl.facade.lnkcomp.condition.PrjLnkCompBkAccQC;
import fl.spl.facade.lnkcomp.constant.LnkCompBankAccConstant;
import fl.spl.facade.lnkcomp.constant.PrjLnkCompRelInfoConstant;
import fl.spl.facade.spl.constant.SplInfoConstant;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
 * @Description: 挂靠公司银行账户信息表 控制层
 */
@Controller
@RequestMapping("/project/prjLnkCompBkAcc")
public class PrjLnkCompBkAccController extends BaseController {

	/**
	 * PrjLnkCompBkAcc 服务层BEAN
	 */
	@Autowired
	private IPrjLnkCompBkAccService prjLnkCompBkAccService;

	@Autowired
    private IPrjLnkCompService prjLnkCompService;

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		String compId = request.getParameter("compId");
        String lxxz = request.getParameter("lxxz");
		ModelAndView view = new ModelAndView("project/prjLnkCompBkAcc/prjCompBankList");
		view.addObject("compId", compId);
        view.addObject("lxxz",lxxz);
        String allowMdfBank = request.getParameter("allowMdfBank");
        view.addObject("allowMdfBank", allowMdfBank);
        String proIntId = request.getParameter("proIntId");//流程实例ID
        view.addObject("proIntId", proIntId);
		BaseLogUtils.newWebLogger("挂靠公司银行账户信息表，跳转到列表页面").setLogOperType(LogOperEnum.REQ)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
				.setWarning(false)
				.info();
		return view;
	}

	/**
	 * 到新增/修改页面
	 */
	@RequestMapping(value = "/toAddPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
		String lnkCompId = request.getParameter("compId");
		String id = request.getParameter("id");
		String disable = request.getParameter("disable");//是否只修改用途
        String isFlow = request.getParameter("isFlow");//是否流程附加信息页面标识
        ModelAndView view = new ModelAndView("project/prjLnkCompBkAcc/prjCompBkAccAdd");
        String lnkCompNm = "";
        String bizTypCd = "";
        if (StringUtils.isNotEmpty(id)) {
            PrjLnkCompBkAccVO prjLnkCompBkAccVO = this.prjLnkCompBkAccService.selectById(Long.valueOf(id));
            if (StringUtils.isNotEmpty(isFlow) && "1".equals(isFlow)) {
                //查询挂靠公司信息
                if (null != prjLnkCompBkAccVO && StringUtils.isNotEmpty(prjLnkCompBkAccVO.getLnkCompId())) {
                    PrjLnkCompVO prjLnkCompVO = this.prjLnkCompService.selectById(prjLnkCompBkAccVO.getLnkCompId());
                    if (null != prjLnkCompVO && StringUtils.isNotEmpty(prjLnkCompVO.getLnkCompNm())) {
                        lnkCompNm = prjLnkCompVO.getLnkCompNm();
                        lnkCompId = String.valueOf(prjLnkCompVO.getId());
                    }
                }
            }
            bizTypCd = prjLnkCompBkAccVO.getBizTypCd();
        }
        view.addObject("bizTypCd", bizTypCd);
        view.addObject("splNm", lnkCompNm);
		List<KeyValueVO> bizTypCdList = this.prjLnkCompBkAccService.searchBizTypCdList();
		List<KeyValueVO> purpCdList = this.prjLnkCompBkAccService.searchCompPurpCdList();
		view.addObject("bizTypCdList", bizTypCdList);
		view.addObject("purpCdListJSON", JSON.toJSON(purpCdList));

		view.addObject("id", id);
		view.addObject("compId", lnkCompId);
		view.addObject("lnkCompNm", lnkCompNm);
        view.addObject("isFlow", isFlow);
        view.addObject("disable", disable);
        view.addObject("currOrgCd", CurrentThreadContext.getCurrentOrgCd());
		BaseLogUtils.newWebLogger("挂靠公司银行账户信息表，跳转到修改页面").setLogOperType(LogOperEnum.REQ)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
				.setWarning(false)
				.info();
		return view;
	}

	/**
	 * 到新增/修改页面
	 */
	@RequestMapping(value = "/toDetailPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toDetail(HttpServletRequest request, HttpServletResponse response) {
		String compId = request.getParameter("compId");
		ModelAndView view = new ModelAndView("project/prjLnkCompBkAcc/prjCompBkAccAdd");
		String id = request.getParameter("id");
		String disable = request.getParameter("disable");//是否只修改用途
		List<KeyValueVO> bizTypCdList = this.prjLnkCompBkAccService.searchBizTypCdList();
		List<KeyValueVO> purpCdList = this.prjLnkCompBkAccService.searchCompPurpCdList();
		view.addObject("bizTypCdList", bizTypCdList);
		view.addObject("purpCdListJSON", JSON.toJSON(purpCdList));
		view.addObject("id", id);
		view.addObject("compId", compId);
		view.addObject("disable", disable);
		view.addObject("detail", "detail");
		BaseLogUtils.newWebLogger("挂靠公司银行账户信息表，跳转到修改页面").setLogOperType(LogOperEnum.REQ)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
				.setWarning(false)
				.info();
		return view;
	}

    /**
     * 到详情页面
     */
    @RequestMapping(value = "/toDetail.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toDetailPage(HttpServletRequest request, HttpServletResponse response) {
        String id = request.getParameter("id");
        String isFlow = request.getParameter("isFlow");//是否流程附加信息页面标识
        ModelAndView view = new ModelAndView("project/prjLnkCompBkAcc/prjCompBkAccDetail");

        String lnkCompId = "";
        String lnkCompNm = "";
        String bizTypCd = "";
        if (StringUtils.isNotEmpty(id)) {
            PrjLnkCompBkAccVO prjLnkCompBkAccVO = this.prjLnkCompBkAccService.selectById(Long.valueOf(id));
            if (StringUtils.isNotEmpty(isFlow) && "1".equals(isFlow)) {
                //查询挂靠公司信息
                if (null != prjLnkCompBkAccVO && StringUtils.isNotEmpty(prjLnkCompBkAccVO.getLnkCompId())) {
                    PrjLnkCompVO prjLnkCompVO = this.prjLnkCompService.selectById(prjLnkCompBkAccVO.getLnkCompId());
                    if (null != prjLnkCompVO && StringUtils.isNotEmpty(prjLnkCompVO.getLnkCompNm())) {
                        lnkCompNm = prjLnkCompVO.getLnkCompNm();
                        lnkCompId = String.valueOf(prjLnkCompVO.getId());
                    }
                }
            }
            bizTypCd = prjLnkCompBkAccVO.getBizTypCd();
        }
        view.addObject("bizTypCd", bizTypCd);
        view.addObject("compId", lnkCompId);
        view.addObject("lnkCompNm", lnkCompNm);
        view.addObject("id", id);
        view.addObject("isFlow", isFlow);
        return view;
    }

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String compId = request.getParameter("compId");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		PrjLnkCompBkAccQC qc = new PrjLnkCompBkAccQC();
		if (StringUtils.isNotEmpty(compId)) {
			qc.setLnkCompId(Long.valueOf(compId));
		}
		page.setCondition(qc);
		Pager pager = this.prjLnkCompBkAccService.searchListPage(page);
		List<PrjLnkCompBkAccVO> list = (List<PrjLnkCompBkAccVO>) pager.getResultList();
		ListPageVO<PrjLnkCompBkAccVO> listPage = new ListPageVO<PrjLnkCompBkAccVO>(list, pager.getTotalCount());
		BaseLogUtils.newWebLogger("查询挂靠公司银行账户信息完成").setLogOperType(LogOperEnum.RESP)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
				.setWarning(false)
				.setKeys("listPage", JSON.toJSONString(listPage))
				.info();
		return listPage;
	}

	/**
	 * 到列表详情页面
	 */
	@RequestMapping(value = "/toListPageDetail.do", method = { RequestMethod.GET})
	public ModelAndView toListPageDetail(HttpServletRequest request, HttpServletResponse response) {
		String compId = request.getParameter("compId");
		ModelAndView view = new ModelAndView("project/prjLnkCompBkAcc/prjCompBankListDetail");
		view.addObject("compId", compId);
		BaseLogUtils.newWebLogger("加载挂靠公司备案账号详情列表页面").setLogOperType(LogOperEnum.RESP)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
				.setWarning(false)
				.info();
		return view;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeById.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		try {
			this.prjLnkCompBkAccService.removeById(Long.valueOf(id));
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
		}

		return result;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeByIds.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeByIds(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String ids = request.getParameter("ids");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(ids)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.newWebLogger("删除挂靠公司备案账号数据,主键参数为空!").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			return result;
		}

		List<Long> idsList = new ArrayList<Long>();
		JSONArray idsArray = JSONArray.fromObject(ids);
		for (Object object : idsArray) {
			idsList.add(Long.valueOf(object.toString()));
		}

		try {
			boolean success = this.prjLnkCompBkAccService.removeByIds(idsList);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_DELETE_FAIL);
				BaseLogUtils.newWebLogger("删除挂靠公司备案账号数据失败!").setLogOperType(LogOperEnum.RESP)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
						.setWarning(false)
						.warn(LogExceptionEnum.COMMON_CODE_0002);
			}
			BaseLogUtils.newWebLogger("删除挂靠公司备案账号数据成功").setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.setKeys("result", JSON.toJSONString(result))
					.info();
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("删除挂靠公司备案账号数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0001);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newWebLogger("删除挂靠公司备案账号数据失败,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}

		return result;
	}

	/**
	 * 得到一条记录
	 *
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.newWebLogger("获取挂靠公司备案账号数据详情,id为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			return result;
		}

		try {
			PrjLnkCompBkAccVO vo = this.prjLnkCompBkAccService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				BaseLogUtils.newWebLogger("获取挂靠公司备案账号数据详情不存在!").setLogOperType(LogOperEnum.RESP)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
						.setWarning(false)
						.warn(LogExceptionEnum.COMMON_CODE_0002);
			}
			result.setData(vo);
			BaseLogUtils.newWebLogger("获取挂靠公司备案账号数据详情").setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.setKeys("result", JSON.toJSONString(result))
					.info();
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("获取挂靠公司备案账号数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0001);
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newWebLogger("获取挂靠公司备案账号数据失败,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}
		return result;
	}

	/**
	 * 新增挂靠公司备案账号数据
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		PrjLnkCompBkAccVO entity = new PrjLnkCompBkAccVO();
		try {
			entity = this.getRequestParamForPrjCompBkAccAdd(request);
			Long id = this.prjLnkCompBkAccService.add(entity);
			result.setData(id);
			BaseLogUtils.newWebLogger("新增挂靠公司备案账号数据成功.DATA:" + JSON.toJSONString(entity)).setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.setKeys("result", JSON.toJSONString(result))
					.info();
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("新增挂靠公司备案账号数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0001);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newWebLogger("新增挂靠公司备案账号数据失败,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}

		return result;
	}

	/**
	 * 修改挂靠公司备案账号数据
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.newWebLogger("修改挂靠公司备案账号数据,id为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			return result;
		}
		PrjLnkCompBkAccVO entity = new PrjLnkCompBkAccVO();
		try {
			entity = this.getRequestParamForPrjCompBkAccModify(request);
			entity.setId(Long.valueOf(id));
			boolean success = this.prjLnkCompBkAccService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
				BaseLogUtils.newWebLogger("修改挂靠公司备案账号数据不存在!").setLogOperType(LogOperEnum.RESP)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
						.setWarning(false)
						.warn(LogExceptionEnum.COMMON_CODE_0002);
			}
			BaseLogUtils.newWebLogger("修改挂靠公司备案账号数据").setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.setKeys("result", JSON.toJSONString(result))
					.info();
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("修改挂靠公司备案账号数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0001);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newWebLogger("修改挂靠公司备案账号数据失败,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}
		return result;
	}

	/**
	 * 获取挂靠公司账号请求参数(新增)
	 * @param request 请求
	 * @return
	 */
	private PrjLnkCompBkAccVO getRequestParamForPrjCompBkAccAdd(HttpServletRequest request)throws BaseException{
		String compId = request.getParameter("compId");
		if (StringUtils.isBlank(compId)) {
			throw new BaseException(BaseExceptionConstant.COMMON_0002, "请先维护挂靠公司基本信息!");
		}
		PrjLnkCompBkAccVO vo = this.getRequestParamForPrdSplBank(request);
		vo.setLnkCompId(Long.valueOf(compId));
		vo.setCrtTm(new Date());
		vo.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
		return vo;
	}

	/**
	 * 获取挂靠公司账号请求参数(修改)
	 * @param request 请求
	 * @return
	 */
	private PrjLnkCompBkAccVO getRequestParamForPrjCompBkAccModify(HttpServletRequest request)throws BaseException{
		PrjLnkCompBkAccVO vo = this.getRequestParamForPrdSplBank(request);
		vo.setMdfTm(new Date());
		vo.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
		return vo;
	}

	/**
	 * 获取挂靠公司账号参数信息
	 * @param request
	 * @return
	 * @throws BaseException
	 */
	private PrjLnkCompBkAccVO getRequestParamForPrdSplBank(HttpServletRequest request)throws BaseException{
        String rcptUnt = request.getParameter("rcptUnt");//收款方
        String purpCd = request.getParameter("purpCd");//账户用途
        String accNo = request.getParameter("accNo");//收款账号
        String bkNm = request.getParameter("bkNm");//开户行
        String bkNo = request.getParameter("bkNo");//开户行行号
        String bizTypCd = request.getParameter("bizTypCd");//账号类型
        String bkRem = request.getParameter("bkRem");//备注
        String rgnPrCd = request.getParameter("rgnPrCd");//区域-省
        String rgnCyCd = request.getParameter("rgnCyCd");//区域-市
        String contTel = request.getParameter("contTel");//联系方式

        String disable = request.getParameter("disable");
        String certNo = request.getParameter("certNo");//收款人身份证号
        String bkResTel = request.getParameter("bkResTel");//银行预留手机号
		String compId = request.getParameter("compId");
        String fileParams = request.getParameter("fileParams");//附件上传信息

        //验证参数
        if (StringUtils.isBlank(rcptUnt)) {
            throw new BaseException(BaseExceptionConstant.COMMON_0001, "收款方不能为空!");
        }
        if (StringUtils.isBlank(accNo) || !StringUtils.isNumeric(accNo)) {
            throw new BaseException(BaseExceptionConstant.COMMON_0001, "收款账号不能为空,并且是数字!");
        }
        if (StringUtils.isBlank(bkNm)) {
            throw new BaseException(BaseExceptionConstant.COMMON_0001, "开户行不能为空!");
        }
        if (StringUtils.isBlank(bkNo) || !StringUtils.isNumeric(bkNo)) {
            throw new BaseException(BaseExceptionConstant.COMMON_0001, "开户行行号不能为空,并且是数字!");
        }
        if (StringUtils.isBlank(bizTypCd)) {
            throw new BaseException(BaseExceptionConstant.COMMON_0001, "账号类型不能为空!");
        }else{
            if(BaseConstant.IS_YESNO_YES_STR.equals(bizTypCd) && StringUtils.isEmpty(disable)){
                if (StringUtils.isBlank(certNo) || !StringUtils.isIdCardNumber(certNo)) {
                    throw new BaseException(BaseExceptionConstant.COMMON_0001, "收款方身份证号不能为空,并且是正确的身份证号格式!");
                }
                if (StringUtils.isBlank(bkResTel) || !StringUtils.checkMobileNumber(bkResTel)) {
                    throw new BaseException(BaseExceptionConstant.COMMON_0001, "银行预留手机号不能为空,并且是正确的手机号格式!");
                }
            }
        }

        List<SysUlFilesRecVO> sysUlFilesRecVOList = new ArrayList<SysUlFilesRecVO>();
        //解析附件上传信息
        if(StringUtils.isNotEmpty(fileParams)){
            List<Map<String, String>> fileParamsList = new ArrayList<Map<String, String>>();
            JSONArray arry = JSONArray.fromObject(fileParams);
            for (int i = 0; i < arry.size(); i++) {
                net.sf.json.JSONObject jsonObject = arry.getJSONObject(i);
                Iterator<?> it = jsonObject.keys();
                HashMap<String, String> hMap = new HashMap<String, String>();
                while (it.hasNext())
                {
                    String key = String.valueOf(it.next());
                    String value = (String) jsonObject.get(key);
                    hMap.put(key, value);
                }
                fileParamsList.add(hMap);
            }
            for (Map<String, String> map : fileParamsList) {
                SysUlFilesRecVO sysUlFilesRecVO = new SysUlFilesRecVO();
                sysUlFilesRecVO.setFileNm(map.get("fileNm"));
                sysUlFilesRecVO.setFilePath(map.get("filePath"));
                sysUlFilesRecVO.setAbsLocPath(PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_ROOT_PATH)+map.get("filePath"));
                sysUlFilesRecVO.setCrtTm(new Date());
                sysUlFilesRecVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
                //TODO 这里应该先读配置  按配置保存   这里先写死后期再改---------------Start
                sysUlFilesRecVO.setSysCd(CurrentThreadContext.getCurrentSysCd());
                sysUlFilesRecVO.setOrgCd("0000");
                sysUlFilesRecVO.setCfgCd(LnkCompBankAccConstant.LNK_COMP_FILE_UPLOAD_CFG_CD);
                sysUlFilesRecVO.setCfgDtlCd(LnkCompBankAccConstant.LNK_COMP_FILE_UPLOAD_CFG_DTL_CD);
                //TODO---------------------------------------------------------End
                //默认验证状态:未验证
                sysUlFilesRecVO.setAudStsCd(PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.DictionaryConstant.CODE_GRP_VALID_STATUS_CD_A));
                sysUlFilesRecVOList.add(sysUlFilesRecVO);
            }
        }
		PrjLnkCompBkAccVO vo = new PrjLnkCompBkAccVO();
		vo.setRcptUnt(rcptUnt.trim());
		vo.setPurpCd(purpCd.trim());
		vo.setAccNo(accNo.trim());
		vo.setBkNm(bkNm.trim());
		vo.setBkNo(bkNo.trim());
		vo.setBizTypCd(bizTypCd);
		vo.setBkRem(bkRem);
		vo.setRgnPrCd(rgnPrCd);
		vo.setRgnCyCd(rgnCyCd);
		vo.setSysUlFilesRecVOList(sysUlFilesRecVOList);
		vo.setIsDel(0);
		if(StringUtils.isNotEmpty(compId)){
			vo.setLnkCompId(Long.valueOf(compId));
		}
		vo.setContTel(contTel);
		vo.setCertNo(certNo);
		vo.setBkResTel(bkResTel);
		return vo;
	}

    /**
     * 启动流程
     */
    @RequestMapping(value = "/addFlowStart.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object addFlowStart(HttpServletRequest request, HttpServletResponse response) {
        String id = request.getParameter("id");
        String procDefKey = request.getParameter("procDefKey");
        String procDefId = request.getParameter("procDefId");
        String procNo = request.getParameter("procNo");

        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if (StringUtils.isEmpty(id)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.newWebLogger("启动流程,id为空").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
                    .setWarning(false)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
            return result;
        }
        FlowStartParamsDTO flowStartParamsDTO = new FlowStartParamsDTO();
        try {
            //流程定义Key和流程定义ID 如果是前端选择的则直接指定,如果不是则系统自动按照配置选择唯一一条记录,如果找不到会提示
            flowStartParamsDTO.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_IN);
            flowStartParamsDTO.setWordsInTheTable(PrjLnkCompRelInfoConstant.FLOW_S_H_LNK);
            flowStartParamsDTO.setProcDefKey(procDefKey);
            flowStartParamsDTO.setProcDefId(procDefId);
            flowStartParamsDTO.setProcNo(procNo);
            flowStartParamsDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
            flowStartParamsDTO.setBusinessKey(id);
            flowStartParamsDTO.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
            flowStartParamsDTO.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
            flowStartParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
            flowStartParamsDTO.setInitiator(String.valueOf(CurrentThreadContext.getCurrentUserId()));
            flowStartParamsDTO.setInitiatorNm(CurrentThreadContext.getCurrentUserName());
            flowStartParamsDTO.setProcPriority(FlowConstant.FLOW_PRIORITY_EMERGENCY);//优先级,可以在界面定义
            flowStartParamsDTO.setBusinessType(FlowConstant.FLOW_BUSINESS_TYP_PRJ_LNK_COMP_BK_ACC);//确认用不用
            flowStartParamsDTO.setModelTyp(LnkCompBankAccConstant.FLOW_MODEL_TYP_LNK_COMP_BANK_ACC);//需要和流程配置中的模块类型匹配
            flowStartParamsDTO.setSearchDesc(CurrentThreadContext.getCurrentOrgDispNm() + "、挂靠公司流程大字段参数未定!");
            DataResultDTO dataResultDTO = this.prjLnkCompBkAccService.addFlowStart(flowStartParamsDTO);
            if (!dataResultDTO.getCode().equals(BaseExceptionConstant.BASE_EXCEPTION_CODE_200)) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL);
            }
            if (null != dataResultDTO.getData()) {
                FlowStartedDTO flowStartedDTO = (FlowStartedDTO) dataResultDTO.getData();
                if (StringUtils.isNotBlank(flowStartedDTO.getNextOperUsrNames())) {
                    result.setInfo("下一个节点操作人:" + flowStartedDTO.getNextOperUsrNames());
                } else {
                    result.setInfo("流程发起成功");
                }
            }
        } catch (BaseException e) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(e.getMessage());
            BaseLogUtils.newWebLogger("启动流程,业务异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(e)
                    .warn(LogExceptionEnum.COMMON_CODE_0001);
            e.getStackTrace();
        } catch (Exception e) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.newWebLogger("启动流程,系统异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(e)
                    .error(LogExceptionEnum.COMMON_CODE_0099);
            e.getStackTrace();
        }
        return result;
    }
}

